package br.pucrio.inf.les.SPLAnalyser.impl.squidplugin.query;

import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.EList;

import antlr.collections.List;
import br.ufrn.dimap.ase.squid.core.facade.Query;
import br.ufrn.dimap.ase.squid.core.models.squidmodel.Asset;
import br.ufrn.dimap.ase.squid.core.models.squidmodel.Feature;
import br.ufrn.dimap.ase.squid.core.models.squidmodel.SquidModel;
import br.ufrn.dimap.ase.squid.core.models.squidmodel.Mapping;
import br.ufrn.dimap.ase.squid.core.models.util.SquidModelContent;
import br.ufrn.dimap.ase.squid.core.models.util.ModelContent;

//Retorna todas as dependecias diretas de um artefato.
public class BuscaTeste implements Query {

	private IProject project;
	private SquidModelContent analysisModelContent;
	private ModelContent queryModelContent;
	private SquidModel queryModel;
	private String squidModelPath = "";
	
	
	
	public SquidModel runQuery(IProject sourceCode) {
		project = (IProject)sourceCode;
		this.squidModelPath = project.getFullPath() + "/Squid/SquidModel.squidmodel";
		analysisModelContent = new SquidModelContent(squidModelPath);				
		
		queryModelContent = new ModelContent();
		queryModel = queryModelContent.getAnalysisModel();
		query();
		return queryModel;
	}

	private void query() {
		Asset asset = null;
		
		asset = analysisModelContent.findMethod("getDescricaoOperacao()", "br.ufrn.sigaa.biblioteca.processos_tecnicos.dominio.HistoricoAlteracaoTitulo");
		
		Mapping mapping = analysisModelContent.findMappingOf(asset);
		
		System.out.println("FEATURES:");
		int i = 0;
		for(i=0; i < mapping.getFeatures().size();i++){
			System.out.println(mapping.getFeatures().get(i).getName());
		}
		
		System.out.println("DEPENDENCIES:");
		for(i=0; i < asset.getDependencies().size();i++){
			System.out.println("name: "+asset.getDependencies().get(i).getName());
			System.out.println("path: "+asset.getDependencies().get(i).getPath()+"\n");
		}
		
		queryModelContent.addFeature(mapping.getFeatures());
		queryModelContent.addAsset(asset.getDependencies());
	}

	public String getName() {
		return this.getClass().getSimpleName();
	}

	@Override
	public String getPath() {		
		return  project.getFullPath() + "/Squid/Queries/"+this.getClass().getSimpleName()+".squidmodel";
	}

}
